<?php

class Adept_Renderer_Message extends Adept_Renderer_Base {

    protected $style;
    protected $class;

    public function setErrorStyle($val)
    {
        $this->setStyle($val, ContextMessage::ERROR);
    }

    public function setWarningStyle($val)
    {
        $this->setStyle($val, ContextMessage::WARNING);
    }

    public function setInformStyle($val)
    {
        $this->setStyle($val, ContextMessage::INFORM );
    }

    public function setInformClass($val)
    {
        $this->setClass($val, ContextMessage::INFORM);
    }

    public function setWarningClass($val)
    {
        $this->setClass($val, ContextMessage::WARNING);
    }

    public function setErrorClass($val)
    {
        $this->setClass($val, ContextMessage::ERROR);
    }

    public function getStyle($type) 
    {
        return isset($this->style[$type]) ? $this->style[$type] : null;
    }

    public function setStyle($style, $type) 
    {
        $this->style[$type] = $style;
    }

    public function getClass($type) 
    {
        return isset($this->class[$type]) ? $this->class[$type] : null;
    }

    public function setClass($class, $type) 
    {
        $this->class[$type] = $class;
    }

    public function render(Adept_Component_Message $component) 
    {
        $message = $component->getMessage();
        if(!is_null($message))	{
            $this->renderMessage($message, $component->getWriter());
        }
    }

    protected function renderMessage(Adept_Message $message, $writer)	
    {
        $attrubutes['class'] = $this->class[$message->getType()];
        $attrubutes['style'] = $this->style[$message->getType()];
        
        $writer->writeHtmlTag('span', $attrubutes);
        $writer->write($message->getTitle());
        $writer->writeHtmlTag('/span');
    }

}